package de.hatraco.funderberg.blackjack.views;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.SwingConstants;

import de.hatraco.funderberg.blackjack.data.DataMISC;
import de.hatraco.funderberg.blackjack.data.GraphicsBlackJack;

public class ResultsDialog extends JDialog {
	
	//Singleton Pattern: Stellt sicher, dass nur eine Instanz von ResultsDialog existiert
	private static ResultsDialog instance = new ResultsDialog();

	public static ResultsDialog getInstance() {
		if(instance == null) {
			instance = new ResultsDialog();
		}
		return instance;
	}
	
	private JLabel bg_result;
	private JLabel hl;
	private JLabel dealerhas;
	private JLabel playerhas;
	private JLabel splitPlayerhas;
	private JLabel result_mainhand;
	private JLabel result_splithand;
	
	private JButton nextplayer;
	private JButton nextround;
	private JButton newgame;
	private JButton quitgame;
	
	//private String link = DataMISC.LINKIMG;
	
	private GraphicsBlackJack img;
	
	private ResultsDialog() {
		
		//Instanziert GraphicsBlackJack (für die Bilder)
		this.img = GraphicsBlackJack.getInstance();
		
		//Legt die Größe des Fensters fest
		this.setSize(400,300);
		//Legt fest, dass die Größe nicht verändert werden kann
		this.setResizable(false);
		//Legt fest, dass das Fenster nicht über das "X" rechts oben geschlossen werden kann
		this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
		//Gibt dem Fenster ein BorderLayout
		this.setLayout(new BorderLayout());
		//Legt den Hintergrund fest
		bg_result = new JLabel(img.getBgdialogdef());
		//Fügt den Hintergrund hinzu
		this.add(bg_result);
		//Gibt dem Hintergrund ein "leeres" Layout
        bg_result.setLayout(null);
        
        //Instanziert, Modifiziert und Positioniert die Elemente
        //JLabels
        hl = new JLabel();
        hl.setFont(DataMISC.ARIAL_BOLD20);
        hl.setForeground(Color.WHITE);
        hl.setBounds(0, 15, 400, 25);
        hl.setHorizontalAlignment(SwingConstants.CENTER);
        hl.setVisible(false);
        
        dealerhas = new JLabel();
        dealerhas.setFont(DataMISC.ARIAL_BOLD20);
        dealerhas.setForeground(Color.WHITE);
        dealerhas.setBounds(0, 60, 400, 25);
        dealerhas.setHorizontalAlignment(SwingConstants.CENTER);
        dealerhas.setVisible(false);
        
        playerhas = new JLabel();
        playerhas.setFont(DataMISC.ARIAL_BOLD20);
        playerhas.setForeground(Color.WHITE);
        playerhas.setBounds(0, 90, 400, 25);
        playerhas.setHorizontalAlignment(SwingConstants.CENTER);
        playerhas.setVisible(false);
        
        splitPlayerhas = new JLabel();
        splitPlayerhas.setFont(DataMISC.ARIAL_BOLD20);
        splitPlayerhas.setForeground(Color.WHITE);
        splitPlayerhas.setBounds(0, 120, 400, 25);
        splitPlayerhas.setHorizontalAlignment(SwingConstants.CENTER);
        splitPlayerhas.setVisible(false);
        
        result_mainhand = new JLabel();
        result_mainhand.setFont(DataMISC.ARIAL_BOLD20);
        result_mainhand.setForeground(Color.WHITE);
        result_mainhand.setBounds(0, 150, 400, 25);
        result_mainhand.setHorizontalAlignment(SwingConstants.CENTER);
        result_mainhand.setVisible(false);
        
        result_splithand = new JLabel();
        result_splithand.setFont(DataMISC.ARIAL_BOLD20);
        result_splithand.setForeground(Color.WHITE);
        result_splithand.setBounds(0, 180, 400, 25);
        result_splithand.setHorizontalAlignment(SwingConstants.CENTER);
        result_splithand.setVisible(false);
        
        //Buttons
        nextplayer = new JButton(img.getBtnexplayer());
        nextplayer.setBounds(240, 225, 120, 40);
        nextplayer.setVisible(false);
        
        nextround = new JButton(img.getBtnexround());
        nextround.setBounds(240, 225, 120, 40);
        nextround.setVisible(false);
        
        newgame = new JButton(img.getBtnewgame());
        newgame.setBounds(240, 225, 120, 40);
        newgame.setVisible(false);
        
        quitgame = new JButton(img.getBtquitgame());
        quitgame.setBounds(40, 225, 120, 40);
        quitgame.setVisible(false);
        
        //Fügt die Elemente dem Hintergrund hinzu
        bg_result.add(hl);
        bg_result.add(dealerhas);
        bg_result.add(playerhas);
        bg_result.add(splitPlayerhas);
        bg_result.add(result_mainhand);
        bg_result.add(result_splithand);
        bg_result.add(nextplayer);
        bg_result.add(nextround);
        bg_result.add(newgame);
        bg_result.add(quitgame);
    }
	
	//Definiert Listener für die Buttons
	public void setResultsListener(ActionListener ae) {
		this.nextplayer.addActionListener(ae);
		this.nextround.addActionListener(ae);
		this.newgame.addActionListener(ae);
		this.quitgame.addActionListener(ae);
	}
	
	//Deaktiviert alle JLabels
	public void resetLabels() {
		dealerhas.setVisible(false);
		playerhas.setVisible(false);
		splitPlayerhas.setVisible(false);
		result_mainhand.setVisible(false);
		result_splithand.setVisible(false);
	}
	
	public JLabel getHl() {
		return hl;
	}

	public void setHl(JLabel hl) {
		this.hl = hl;
	}

	public JLabel getDealerhas() {
		return dealerhas;
	}

	public void setDealerhas(JLabel dealerhas) {
		this.dealerhas = dealerhas;
	}

	public JLabel getPlayerhas() {
		return playerhas;
	}

	public void setPlayerhas(JLabel playerhas) {
		this.playerhas = playerhas;
	}

	public JLabel getSplitPlayerhas() {
		return splitPlayerhas;
	}

	public void setSplitPlayerhas(JLabel splitPlayerhas) {
		this.splitPlayerhas = splitPlayerhas;
	}

	public JLabel getResult_mainhand() {
		return result_mainhand;
	}

	public void setResult_mainhand(JLabel result_mainhand) {
		this.result_mainhand = result_mainhand;
	}

	public JLabel getResult_splithand() {
		return result_splithand;
	}

	public void setResult_splithand(JLabel result_splithand) {
		this.result_splithand = result_splithand;
	}
	
	public JButton getNextplayer() {
		return nextplayer;
	}

	public void setNextplayer(JButton nextplayer) {
		this.nextplayer = nextplayer;
	}

	public JButton getNextround() {
		return nextround;
	}

	public void setNextround(JButton nextround) {
		this.nextround = nextround;
	}

	public JButton getNewgame() {
		return newgame;
	}

	public void setNewgame(JButton newgame) {
		this.newgame = newgame;
	}

	public JButton getQuitgame() {
		return quitgame;
	}

	public void setQuitgame(JButton quitgame) {
		this.quitgame = quitgame;
	}	
}
